﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace lutianqi.Helpers
{
    public class WeekConverter : IValueConverter
    {
        //根据当前这条预报信息的日期返回对应的星期
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
                return GetCNWeek(DateTime.Parse(value.ToString().Replace("年", "-").Replace("月", "-").Replace("日", "")).AddDays(double.Parse(parameter.ToString())));
            else
                return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        //使用DayOfWeek处理
        public string GetCNWeek(DateTime dt)
        {
            string cnweek = string.Empty;
            switch (dt.DayOfWeek.ToString())
            {
                case "Monday":
                    cnweek = "星期一";
                    break;
                case "Tuesday":
                    cnweek = "星期二";
                    break;
                case "Wednesday":
                    cnweek = "星期三";
                    break;
                case "Thursday":
                    cnweek = "星期四";
                    break;
                case "Friday":
                    cnweek = "星期五";
                    break;
                case "Saturday":
                    cnweek = "星期六";
                    break;
                case "Sunday":
                    cnweek = "星期日";
                    break;
            }
            return cnweek;
        }

    }
}
